﻿using BasicInformation.ApiWrite.Application.Command.Category;
using BasicInformation.ApiWrite.Application.Handler.Category;
using BasicInformation.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BasicInformation.ApiWrite.Controllers
{
    /// <summary>
    /// 产品类别——写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class CategoryController : ControllerBase
    {
        private readonly IMediator mediator;

        public CategoryController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 产品类别添加接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddCategory(AddCategoryCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 产品类别修改接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateCategory(UpdateCategoryCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 产品类别删除接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<int>> DelCategory([FromQuery]DelCategoryCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
